<?php
class m_employee extends spModel {
	public $pk = 'employee_id';
	public $table = 'employee';
	/**
	 * 表中内部字段有: nickname realname workid sfzh password
	 * 表中外部字段有:	article_id
	 * ManyToMany表为:
	 */
	var $linker = array (
// 			array (
// 					'type' => 'manytomany', // 多对多关联
// 					'map' => 'whohas', // 关联的标识
// 					'midclass' => 'farm_user2fruit', // 关联的中间表
// 					'mapkey' => 'fruitid', // 关联的字段
// 					'fclass' => 'farm_user', // 对应表的数据类
// 					'fkey' => 'uid', // 对应表的关联字段
// 					'enabled' => true 
// 			),
			/**
			 *  与文章,HasMany关系
			 */			
			array (
					'type' => 'hasmany', // 一对多关联
					'map' => 'article', // 关联的标识
					'mapkey' => 'article_id',
					'fclass' => 'm_article',
					'fkey' => 'article_id',
					
					'enabled' => true 
			) ,
			/**
			 * 与部门,ManyToMany
			 */
			array(
				'type' => 'manytomany',
				'map' => 'department',
				'midclass' => 'mid_department_employee', // 关联的中间表
				'mapkey' => 'employee_id', // 关联的字段
				'fclass' => 'm_department', // 对应表的数据类
				'fkey' => 'department_id', // 对应表的关联字段
				'enabled' => true
			),
	);
	var $verifier = array(
			'rules' => array(
					'nickname' => array(
							),	
					'realname' => array(
							),
					'workid' => array(
							),
					'sfzh' => array(
							),
					'password' => array(
							)
				));
	
	/**
	 * 检查用户名,密码是否匹配
	 *
	 * @param string $username
	 * @param string $password
	 */
	function check_user($username, $password) {
		if ($result = $this->find ( array (
				'username' => $username,
				'password' => $password
		) )) {
			// TODO 使用spAcl 设置权限
			
			$this->update(array('employee_id' => $result['employee_id']), array('last_time'=>date('Y-m-d H:i',time())));
			
			$_SESSION ['user_info'] = $result;
			return true;
		} else {
			return false;
		}
	}
}